<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=7" />
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<title>提交流程对话框</title>
<%-- 全路径--%>
<c:set var="baseURL" value="http://${header.host}${pageContext.request.contextPath}" scope="request" /> 
 <script type="text/javascript">
 	var baseURL = "${baseURL}";
 </script>
</head>


<body class="FrameWindow">
	<div class="cont-table">
		<div class="table-normal">
		   <form id="opinionform" method="post">
        	<input type="hidden" name="boId" id="boId" value="${param.boId}" class="field"/>
        	<input type="hidden" name="mainBoId" id="mainBoId" value="${param.mainBoId}" class="field"/>
        	<input type="hidden" name="busiType" id="busiType" value="${param.busiType}" class="field"/>
        	<input type="hidden" name="flowId" id="flowId" value="${param.flowId}" class="field"/>
        	<input type="hidden" name="worklistId" id="worklistId" value="${param.worklistId}" class="field"/>
        	<input type="hidden" name="routeId" id="routeId" value="${param.routeId}" class="field"/>
        	<input type="hidden" name="parentNodeInstanceId" id="parentNodeInstanceId" value="${param.parentNodeInstanceId}" class="field"/>
        	<input type="hidden" name="handlerValue" id="handlerValue" value="" />
        	<input type="hidden" name="handlerText" id="handlerText" value="" />
				<table class="tb_borderNone">
					<c:if  test="${!isStart }">
					<tr>
						<td class="text-right text-6">流程意见填写：</td>
						<td class="buttons">
							<button id="btnSaveMyOpinion" class="btn btn-small btn-blue">保存为我的常用意见</button>
							<button id="btnDelMyOpinion" class="btn btn-small btn-orange">删除我的常用意见</button>
							<button id="btnClearOpinion" class="btn btn-small btn-default">清空意见</button>
						</td>
					</tr>
					<tr class="border-top">
						<td class="text-right text-6">我的常用意见：</td>
						<td>
							<select name="myOpinion" id="myOpinion" style="width: 350px">
								<option value=''>--请选择--</option>
								<c:forEach var="o" items="${myOpinions}">
									<option value="${o.id}">${o.opinion}</option>
								</c:forEach>
						</select>
						</td>
					</tr>
					<tr>
						<td class="text-right text-6">意见填写：</td>
						<td>
							<textarea cols="100" rows="4" name="opinion" id="opinion" style="width: 350px;"
								validate="{maxlength:200}"></textarea>
						</td>
					</tr>
					</c:if>
					<tr>
						<td class="text-right text-6">路由选择：</td>
						<!-- <td>
							<select>
								<option>--请选择--</option>
							</select>
						</td> -->
						<td >${routeSelect.routeName}&nbsp;&nbsp;->&nbsp;&nbsp;${routeSelect.nextNodeName}</td>
					</tr> 
 					<c:if test="${routeSelect.hasHandlerSelect && orgType != 20}">
					<tr>
						<td class="text-right text-6">下一环节处理人：</td>
						<td class="buttons">
							<button id="btnReselected" class="btn btn-normal btn-default">重新选择</button>
							<button id="btnDeselected" class="btn btn-normal btn-default">删除</button>
							<button id="btnAllselected" class="btn btn-normal btn-default">全选</button>
						</td>
					</tr>
						<tr>
							<td class="text-right text-6">处理人选择：</td>
							<td align="left" id="handlerList">
							</td>	
						</tr>
					</c:if>
				</table>
			</form>
		</div>
	</div>
	<!-- cont-table -->
	 <script type="text/javascript">
  	var hasHandlerSelect = ${routeSelect.hasHandlerSelect};
  	  //保存我的常用意见
  	  $("#btnSaveMyOpinion").click(function(){
  		var val = $("#opinion").val()
  		if($.trim(val)==''){
  			/* LG.showWarn */
  			BT.showError("请先填写意见!");
  			return false;
  		}else if($.trim(val).length > 50){
  			/* LG.showWarn */
  			BT.showError("我的常用意见长度不可超过50个字符!");
  			return false;
  		}
  		  $.post("${baseURL}/process/myopinion/personopinionsave/save.do", 
  				  {opinion : $.trim(val)}, 
  				  function(data){
  			  		if(data.hasOk){
  			  			BT.showSuccess("已保存");
  			  		var $OPT = $("<option>");
		  				$OPT.attr("value", data.bean.id);
		  				$OPT.text($("#opinion").val());
		  				$("#myOpinion").append($OPT);
  			  		}else{
  			  			BT.showError(data.message);
  			  		}
  		  });
  		return false;
  	  });
  	 //删除我的常用意见
  	  $("#btnDelMyOpinion").click(function(){
  		var sels = $("#myOpinion").children(":selected");
  		if(!sels || sels.length == 0 || sels.val()==''){
  			/* LG.showError *///showError("请先从下面的“我的常用意见”下拉选择要删除的意见项!");
  			BT.showError("请先从下面的“我的常用意见”下拉选择要删除的意见项!");
  			return false;
  		}
  		$.post("${baseURL}/process/myopinion/personopiniondelete/delete.do", 
				  {ids : sels.val()}, 
				  function(data){
			  		if(data.hasOk){
			  			BT.showSuccess("已删除!");
			  			sels.remove();
			  		}else{
			  			BT.showError(data.message);
			  		}
		  });
  		return false;
	  });
  	 //清空意见填写框中的信息
  	  $("#btnClearOpinion").click(function(){
  		$("#opinion").val("");
  		return false;
	  });
  	 //重新选人(先删除已有处理人再加入重选的处理人)
  	  $("#btnReselected").click(function(){
	  		/* $(this).sdAddressBook({type:'${orgType}', manage:<c:if test="${orgType == 40}">10</c:if><c:if test="${orgType != 40}">3</c:if>, multi: 'n', 
	  			onReturn : function(users){
 	  				if(!users || users.outputValue <= 0) return false;
 	  				var oldchecked = $("input[name='handler']");
 	  				if(!oldchecked || oldchecked.length >0){
 	  					oldchecked.parent().remove();
 	  				}
	  				var handlers = $.sdAddressBook.parseValues(users.outputValue);
 	  				for(var i = 0 ;i < handlers.length; i++){
	  					var handler = handlers[i];
	  					var $span = $("<label class='leb'>");
	  					$span.append('<input type="checkbox" name="handler" value="'+handler.id+'" checked="checked"/>'+handler.name);
	  					$span.append('&nbsp;&nbsp;&nbsp;&nbsp;</leb>');
	  					$("#handlerList").append($span);
 	  				}
  	  			 return false;
	  		}}); */
	  		$(this).zljgAddressBook({openType:'dialog', url:baseURL+'/zljgaddressbook/addressbook/frame.do', type:16, selectType: 16, num: 1, defaultParams:JSON.stringify({level:1,isCurrentOrigion:true}), idFieldId:null, textFieldId:null,includeParent:0, callback:function(msg){
	  			if(!msg || msg.data.length <= 0) return false;
  				var oldchecked = $("input[name='handler']");
  				if(!oldchecked || oldchecked.length >0){
  					oldchecked.parent().remove();
  				}
  				for(var i in msg.data){
  					var handler = msg.data[i];
  					var $span = $("<label class='leb'>");
  					$span.append('<input type="checkbox" name="handler" value="'+handler.code+'" checked="checked"/>'+handler.text);
  					$span.append('&nbsp;&nbsp;&nbsp;&nbsp;</leb>');
  					$("#handlerList").append($span);
  				}
  			 	return false;
	  		}});
    		return false;
	  });
  	 
  	 //删除
  	 $("#btnDeselected").click(function(){
  		var handler = $("input[name='handler']:checked");
  		if(!handler || handler.length ==0){
   		 // LG.showWarn("没有选定的处理人!");
   		 BT.showError("没有选定的处理人!");
   		  return false;
   	    }
  		handler.parent().remove();
  		return false;
  	 });
  	 
  	 //全选
  	 $("#btnAllselected").click(function(){
  		//var state = $("input[name='handler']:first").attr("checked");
  		/* if($("input[name='handler']").attr("checked")){
  			$("input[name='handler']").removeProp("checked");
  		}else{ */
    		$("input[name='handler']").prop("checked", true);
  		//}
  		return false;
  	 });
      //编辑，新增
	  var mainform = $("#opinionform");
	  //mainform.ligerForm();
      //添加验证
     jQuery.metadata.setType("attr", "validate"); 
    //表单验证
     // LG.validate(mainform);
     $("#myOpinion").change(function(){
    	 var sels = $(this).children("option:selected");
    	 if(sels.length >= 0 && $.trim(sels.val())!='')
    		 $("#opinion").val(sels.text());
    	 return false;
     });
     
     //提交
     function FF_Submit(callback, isStart){ 
    	 var action = "${baseURL}/process/gtasks/submit/next.do";//提交
    	 if(isStart) 
    		 action = "${baseURL}/process/gtasks/submit/start.do";//发起
    	 var handler = $("input[name='handler']:checked");
    	 <c:if test="${orgType != 20}">
 	   	 if(hasHandlerSelect && (!handler || handler.length ==0)){
	   		  //LG.showWarn("没有选定的处理人!", callback);
	   		  BT.showWarning("没有选定的处理人！",callback);
	   		  return false;
	   	 }
 	   	 </c:if>
 	   	/*  var str = ""; 
 	   	 //20!@!罗广亨!@!2c90815444b8eef00144b8f0ca0800a6,20!@!余君劭!@!2c90815444b8eef00144b8f0ca0900b0
 	   	 $("input[name='handler1']:checked").each(function(){
 	   		$("#handlerList").append('<input type="hidden" name="handler" value="'+$(this).val()+'" />');
 	   	 }); */
 	   	 	loader.open($('body'));
		    mainform.attr("action", action);
			BT.submitForm(mainform, function(data){
				loader.close($('body'));
              if (data && data.hasOk) {  
                    BT.showSuccess('操作成功!',function(){
						callback(data);
                    },function(){
						callback(data);
                    });
              } else {
              		BT.showError('操作失败:'+data.message,function(){
              			callbcak(data);
              		},function(){
						callback(data);
                    });
              }
          });
    }
  </script>
</body>
</html>
